﻿using BW.Demo.Domain.Entities;
using BW.Demo.ErrorCode;
using BW.Demo.Infrastructure.Interfcaes;
using BW.Demo.WebApi.Applications.Commands;
using BW.Demo.WebApi.Dtos;
using MediatR;

namespace BW.Demo.WebApi.Applications.CommandHandlers
{
    public class GoodsQueryCommandHandler : IRequestHandler<GoodsQueryCommand, APIResult<List<ProductName>>>
    {
        IBaseRespitory<ProductName> baseRespitory;
        public GoodsQueryCommandHandler(IBaseRespitory<ProductName> baseRespitory)
        {
            this.baseRespitory = baseRespitory;
        }
        public Task<APIResult<List<ProductName>>> Handle(GoodsQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProductName>> result = new APIResult<List<ProductName>>();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();
            var list=baseRespitory.GetAll();
            result.Data=list.ToList();
            return Task.FromResult(result);


        }
    }
}
